/********************************************************************************
*                 Copyright (C) 2011 - Las Venturas Playground                  *
*                      http://iv-mp.nl | http://lvp-iv.com                      *
*                                                                               *
*    This program is free software: you can redistribute it and/or modify       *
*    it under the terms of the GNU General Public License as published by       *
*    the Free Software Foundation, either version 3 of the License, or          *
*    (at your option) any later version.                                        *
*                                                                               *
*    This program is distributed in the hope that it will be useful,            *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
*    GNU General Public License for more details.                               *
*                                                                               *
*    You should have received a copy of the GNU General Public License          *
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
*                                                                               *
*********************************************************************************
*                                                                               *
*  Las Venturas Playground - clientscript: Register.nut                         *
*                                                                               *
*  This file will hold the LVP:IV Register window                               *
*                                                                               *
********************************************************************************/

//Definitions
local screensize = guiGetScreenSize();
local guiRegister = {};

// Register window
guiRegister.windowRegister <- GUIWindow();
guiRegister.windowRegister.setPosition(screensize[0]/2 - 245/2, screensize[1]/2 - 160/2, false);
guiRegister.windowRegister.setSize(245.0, 160.0, false);
guiRegister.windowRegister.setText("LVP:IV Register");
guiRegister.windowRegister.setVisible(false);

guiRegister.windowRegistershown <- false;

// Register window: username
guiRegister.txtUsername <- GUIText();
guiRegister.txtUsername.setParent(guiRegister.windowRegister.getName());
guiRegister.txtUsername.setPosition(10.0, 10.0, false);
guiRegister.txtUsername.setText("Username");

// Register window: password
guiRegister.txtPassword <- GUIText();
guiRegister.txtPassword.setParent(guiRegister.windowRegister.getName());
guiRegister.txtPassword.setPosition(10.0, 45.0, false);
guiRegister.txtPassword.setText("Password");

// Register window: e-mail
guiRegister.txtEmail <- GUIText();
guiRegister.txtEmail.setParent(guiRegister.windowRegister.getName());
guiRegister.txtEmail.setPosition(10.0, 80.0, false);
guiRegister.txtEmail.setText("E-mail");

// Register window: username editbox
guiRegister.editUsername <- GUIEditBox();
guiRegister.editUsername.setParent(guiRegister.windowRegister.getName());
guiRegister.editUsername.setPosition(100.0, 10.0, false);
guiRegister.editUsername.setSize(125.0, 20.0, false);
guiRegister.editUsername.setText(getPlayerName(getLocalPlayer()));  

// Register window: password editbox
guiRegister.editPassword <- GUIEditBox();
guiRegister.editPassword.setParent(guiRegister.windowRegister.getName());
guiRegister.editPassword.setPosition(100.0, 40.0, false);
guiRegister.editPassword.setSize(125.0, 20.0, false);
guiRegister.editPassword.setProperty("MaskText", "true");

// Register window: e-mail editbox
guiRegister.editEmail <- GUIEditBox();
guiRegister.editEmail.setParent(guiRegister.windowRegister.getName());
guiRegister.editEmail.setPosition(100.0, 70.0, false);
guiRegister.editEmail.setSize(125.0, 20.0, false);

// Register window: Register button
guiRegister.btnRegister <- GUIButton();
guiRegister.btnRegister.setParent(guiRegister.windowRegister.getName());
guiRegister.btnRegister.setPosition(10.0, 105.0, false);
guiRegister.btnRegister.setSize(60.0, 25.0, false);
guiRegister.btnRegister.setText("Register");

// Register window: reset button
guiRegister.btnReset <- GUIButton();
guiRegister.btnReset.setParent(guiRegister.windowRegister.getName());
guiRegister.btnReset.setPosition(170.0, 105.0, false);
guiRegister.btnReset.setSize(60.0, 25.0, false);
guiRegister.btnReset.setText("Reset");
/*
// Help window: close button
guiRegister.btnClose <- GUIButton();
guiRegister.btnClose.setParent(guiRegister.windowRegister.getName());
guiRegister.btnClose.setPosition(160.0, 20.0, false);
guiRegister.btnClose.setSize(50.0, 25.0, false);
guiRegister.btnClose.setText("Close");
*/
// Register window: 
function onButtonClick(btnName, bState)
{
    // Register window: Register button behavior.
    if(btnName == guiRegister.btnRegister.getName())
    {
        //triggerServerEvent("registerPlayer", editUsername.getText(), editPassword.getText() , editEmail.getText())
    }
    // Register window: (Temporary) Close button behavior.
    if(btnName == guiRegister.btnClose.getName())
    {
        guiRegister.windowRegister.setVisible(false);
        guiRegister.windowRegistershown = false;
        guiToggleCursor(false);
    }
    // Register window: Reset button behavior.
    if(btnName == guiRegister.btnReset.getName())
    {
        guiRegister.editUsername.setText("");
        guiRegister.editPassword.setText("");
        guiRegister.editEmail.setText("");
    }    
}
addEvent("buttonClick", onButtonClick);

function onPlayerCommand(command)
{
    if(command == "/register2")
    {
        addChatMessage("Hello, World!", 0x0000FFFF); 
        guiRegister.windowRegister.setVisible(!guiRegister.windowRegistershown);
        guiRegister.windowRegistershown = !guiRegister.windowRegistershown;
        guiToggleCursor(true);
    }
}
addEvent("playerCommand", onPlayerCommand);